<!-- 交易订单查询 -->
<template>
    <div>
        <!-- sub-title="购物基金释放" -->
        <a-page-header
            style="border: 1px solid rgb(235, 237, 240);background:#fff"
            :title="'用户'+phone+'-'+userName+'的交易统计'"
            @back="() => $router.go(-1)"
        >
        <div class="table-page-search-wrapper">
            <a-form layout="inline">
                <a-row :gutter="48">
                      <a-col :md="12" :sm="24">
                        <a-form-item label="订单日期">
                            <a-range-picker  :format="dateFormat"    @change="onChange" allowClear/>
                        </a-form-item>
                    </a-col>
                    <a-col :md="8" :sm="24">
                        <a-form-item >
                            <a-button type="primary" @click="getData()">查询</a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>

        <a-table rowKey="id" :loading="isload" :columns="columns" bordered  :data-source="dataList" size="small" :scroll="{ x: 1200, }">
              <template slot="statType" slot-scope="text, record">
                <a-tag color="pink" v-if="record.statType==1" >本人</a-tag>  
                <a-tag color="red" v-else-if="record.statType==2" >直推</a-tag>  
                <a-tag color="orange" v-else-if="record.statType==3" >间推</a-tag> 
                <a-tag color="green" v-else-if="record.statType==4" >团队(直推+间推)</a-tag>  
            </template>
        </a-table>
        </a-page-header>
    </div>
</template>

<script>
import { columns } from './table';
import moment from 'moment';
import {  queryUserStat } from '@/api/member';
export default {
    data () {
        return {
            dateFormat: 'YYYY-MM-DD',
            phone:this.$route.query.phone,
            userName:this.$route.query.userName,
            brandId:this.$route.query.brandId,
            dataList: [],
            total: 0,
            isload: false,
            page: 1,
            size: 10,
            userId:this.$route.query.userId,
            gtCreateTime:'',
            ltCreateTime:'',
            columns,
            
        };
    },
    created(){
        this.getData()
    },
    methods: {
        moment,
        getDay(dates) {
            var dd = new Date();
            var n = dates || 0;
            dd.setDate(dd.getDate() + n);
            var y = dd.getFullYear();
            var m = dd.getMonth() + 1;
            var d = dd.getDate();
            m = m < 10 ? "0" + m : m;
            d = d < 10 ? "0" + d : d;
            return  y + "-" + m + "-" + d;
            },
         onChange(date, dateString) {
            console.log(date, dateString);
            this.gtCreateTime = dateString[0]
            this.ltCreateTime = dateString[1]
            this.getData()
        },
        // 查询交易订单
        getData(){
            let _this = this
            _this.isload = true
            const params = {
                'userId':_this.userId,
                'gtDate':_this.gtCreateTime,
                'ltDate':_this.ltCreateTime,
            }
          
            queryUserStat(params)
            .then(res=>{
                _this.isload = false
                if(res.success){
                    _this.dataList = res.data
                    if(res.data.length>0){
                        var data={
                            statType:4,
                            failedAmount:Number(res.data[1].failedAmount+res.data[2].failedAmount).toFixed(2),
                            failedCount:res.data[1].failedCount+res.data[2].failedCount,
                            succeedAmount:Number(res.data[1].succeedAmount+res.data[2].succeedAmount).toFixed(2),
                            succeedCount:res.data[1].succeedCount+res.data[2].succeedCount,
                            totalRebate:Number(res.data[1].totalRebate+res.data[2].totalRebate).toFixed(2),
                            totalShopFund:Number(res.data[1].totalShopFund+res.data[2].totalShopFund).toFixed(2),
                        }
                        _this.dataList.push(data)
                    }
                
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
      
    }
}

</script>
<style scoped>
.status0{
    color: #faad14
}
.status1{
    color: #52c41a
}
.status2{
    color: #f5222d
}
.status3{
    color: #faad14
}
</style>